package com.firmboy.redis.hello.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

/**
 * redis的连接操作类
 *
 * @author firmboy
 * @create 2018-03-13 下午5:22
 **/
@Repository
public class RediaDao {

    @Autowired
    private StringRedisTemplate template;

    public void setKey(String key,String value){
        ValueOperations<String, String> ops = template.opsForValue();

        ops.set(key, value,1, TimeUnit.MINUTES);
    }

    public String getKey(String key){
        ValueOperations<String, String> ops = template.opsForValue();
        String s = ops.get(key);
        return s;
    }

}
